<template>
	<!-- 潜客编辑 -->
	<div>
		<div class="edit-top">
			添加信息
			<i class="el-icon-close" @click='cancel'></i>
		</div>
		<div class="edit-content">
			<div class="edit-title">潜客信息</div>
			<div class="edit-item">
				<label>客户姓名</label><input v-model="info.passengerName" type="text" />
			</div>
			<div class="edit-item">
				<label>车牌号</label><input v-model="info.licensePlateNumber" type="text" />
			</div>
			<div class="edit-item">
				<label>手机号</label><input v-model="info.passengerMobile" type="text" />
			</div>
			<div class="edit-item">
				<label>所属区域</label><select v-model="info.areaId">
					<option v-for="item in area_list" :value="item.id">{{item.name}}</option>
				</select>
			</div>
			<div class="edit-item">
				<label>是否运营</label><select v-model="info.isOperationCar">
					<option v-for='item in dict.property' :value="item.value">{{item.type}}</option>
				</select>
			</div>
			<div class="edit-item">
				<label>客源</label><select v-model="info.passengerSource">
					<option v-for='item in dict.passengerSource' :value="item.value">{{item.type}}</option>
				</select>
			</div>
			<div class="edit-item">
				<label>级别</label><select v-model="info.passengerLevel">
					<option v-for='item in dict.passengerLevel' :value="item.value">{{item.type}}</option>
				</select>
			</div>
			<div class="edit-item">
				<label>客户类型</label><select v-model="info.passengerType">
					<option v-for='item in dict.passengerType' :value="item.value">{{item.type}}</option>
				</select>
			</div>
			<div class="edit-item">
				<label>采购数量</label><input v-model="info.purchaseAmount" type="number" />
			</div>
			<div class="edit-item">
				<label>预计采购时间</label><el-date-picker v-model="info.estimatedPurchaseTime" type="date" value-format="yyyy-MM-dd" placeholder="预计采购时间">
				</el-date-picker>
			</div>
			<div class="edit-item">
				<label>车辆注册日期</label><el-date-picker
				      v-model="info.vehicleRegistrationDate"
				      type="date"
					  value-format="yyyy-MM-dd"
				      placeholder="车辆注册日期">
				 </el-date-picker>
			</div>
			<div class="edit-item">
				<label>需求说明</label><input v-model="info.requirement" type="text" />
			</div>
			<div class="edit-item" v-if="type == 0"><label>业务员</label>
				<el-select v-model="info.sysUserId" filterable placeholder="请选择">
					<el-option v-for="item in staff_list" :key="item.id" :label="item.chineseName" :value="item.id">
					</el-option>
				</el-select>
			</div>
		</div>
		<div class="edit-bottom">
			<span @click='cancel'>取消</span>
			<el-button @click='save' type="primary">保存</el-button>
		</div>
	</div>
</template>

<script>
	let _this;
	export default {
		props: ['id','type'],
		data() {
			return {
				dict: '',
				area_list: [],
				staff_list: [],
				info: {
					passengerName: '',
					licensePlateNumber: '',
					passengerMobile: '',
					purchaseAmount: '',
					areaId: '',
					requirement: '',
					passengerSource: 0,
					passengerType: 0,
					isOperationCar: 0, 
					estimatedPurchaseTime: '',
					sysUserId: ''

				}
			}
		},
		created() {
			_this = this;
		},
		mounted() {

			this.get_dict();
			this.get_area();
			if (this.type == 0) {
				this.get_staff();
			}
			this.get_info();
		},
		methods: {
			get_staff() {
				this.$axios.post(this.$global.serverIp + 'admin/sysStaff/findPage', {
						"limit": "10000",
						"page": "1"
					})
					.then(function(res) {
						if (res != '') {
							_this.staff_list = res.data.list;
						}

					})
			},
			get_info() {
				this.$axios.get(this.$global.serverIp + 'crm/crmPassenger/detail?id=' + this.id)
					.then(function(res) {
						if (res != '') {
							_this.info = res.data;
						}

					})
			},
			get_area() {
				this.$axios.post(this.$global.serverIp + 'admin/sysProvince/findPage', {
						"limit": "10000",
						"page": "1"
					})
					.then(function(res) {
						if (res != '') {
							_this.area_list = res.data.list;
							_this.info.areaId = res.data.list[0].id;
						}

					})
			},
			get_dict() {
				this.$axios.get(this.$global.serverIp + 'admin/dict/findDict?keyword=crmPassenger')
					.then(function(res) {
						if (res != '')
							_this.dict = res.data;
					})
			},
			save() {
				if (this.info.passengerName == "") {
					this.$popup.open('姓名不能为空');
					return;
				}
				// if (this.info.licensePlateNumber == "") {
				// 	this.$popup.open('车牌号不能为空');
				// 	return;
				// }
				if (this.info.passengerMobile == "") {
					this.$popup.open('手机号不能为空');
					return;
				}
				if (this.info.purchaseAmount == "" || this.info.purchaseAmount == 0) {
					this.$popup.open('采购数量不能为空');
					return;
				}
				
				if(this.type == 0){
					this.$axios.post(this.$global.serverIp + 'crm/crmPassenger/passengerModifySalesman', _this.info)
						.then(function(res) {
							if (res != '') {
								_this.$axios.post(_this.$global.serverIp + 'crm/crmPassenger/update', _this.info)
									.then(function(res) {
										if (res != '') {
											_this.success('编辑成功');
										}
									})
							}
						})
				}else{
					this.$axios.post(this.$global.serverIp + 'crm/crmPassenger/update', _this.info)
						.then(function(res) {
							if (res != '') {
								_this.success('编辑成功');
							}
						})
				}
				
			},
			success(content) {
				this.$alert(content, '提示', {
					confirmButtonText: '确定',
					callback: action => {
						_this.$emit("saveEdit", 2);
					}
				});
			},
			cancel() {
				this.$emit("saveEdit", 1);
			}
		}
	}
</script>
